package ro.ubbcluj.cs.damate.plugin.utils;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public final class SpringUtils {
	
	private static final String APPLICATION_CONTEXT_PATH = "/resources/spring-config.xml";
	
	private static ApplicationContext applicationContext;
	
	private SpringUtils() {}
	
	public static void loadSpringConfigurations() {
		getApplicationContext();
	}
	
	public static Object getBean(String beanName) {
		return getApplicationContext().getBean(beanName);		
	}	
	
	private static final ApplicationContext getApplicationContext() {
		if (applicationContext == null) {
			applicationContext = new ClassPathXmlApplicationContext(APPLICATION_CONTEXT_PATH, SpringUtils.class);
		}
		return applicationContext;
	}
}
